define(function(require,exports,module) { 
    var myPub = require('./public');
    // 广告模块
    var myAdsModel = require('./adsModel');
    // 地区管
    var areaList = require('./areaList');

    // 曝光可视区域元素
    var visualArea = require('./visualAreaInfo');

    var oWindow = $(window);
    var oWrap = $('.js_wrap');                      // wrap 部分
    var oHeader = $('.js_headerBox');               // 头部
    var oFooter = $('.js_footer');                  // 底部
    var oSearchBox = $('.js_searchBox');            // 搜索
    var oContain = $('.js_contain');                // 页面内容区域
    var oSlidePageWrap = $('.js_slidePageWrap');    // 滑动页面
    var oSlidePage = $('.js_slidePage');            // 滑动页面容器
    var oSideBox = $('.js_sideBox');		        // 侧边按钮框
    var oGoTop = $('.js_goTop');                    // 回到顶部
    var popCloseBtn=$('.js_layer_AdsCloseBtn');     // 弹窗关闭按钮
    var oLoadingPage = $('.js_loadingPage');

    var oSildeNav = $('.js_sildeNav ');             // 导航栏
    var oSildeNavScroll = $('.js_sildeNavScroll');  // 导航滚动条容器
    var oSildeNavUl = $('.js_sildeNavUl');          // 导航滚动条ul

    var oSlidePageScroll = $('.js_slidePageScroll');
    var oSildeNavJRoll = new myPub.ScrollBar();     // 导航滚动条
    var nDisScrollLi = 0;                           // 导航滚动偏移值

    var oGoods_showTwo = $('.js_goods_showTwo');    // 并排产品容器

    var oAIEntrance = $('.js_voiceEntrance');    //智能语音入口

    var oSlideDown = $('.js_slideDown');        //点击下拉弹窗按钮
    var oSlideUp = $('.js_slideUp');           //点击上拉弹窗按钮
    var oNewNavPop = $('.js_newSlideNavPop');         //新导航弹窗
    var oPackUpBox = $('.js_packUpBox');             //弹窗的
    var oCloseShawdow = $('.js_closeSlideNav');      //剩下的阴影

    var lazLoading = new myPub.lazLoadingImg();

    var timeOutClock = null;  //返现专区跳转的定时器

    var perLimit = 20;
    var resizeTimer = null;
    var counponNewData = JSON.parse(sessionStorage.getItem('judgeNew_friend_coupons')); // 获取新人用户的优惠券数据
    var nNewFriend = '';                                // 判断是不是新用户
    nNewFriend = sessionStorage.getItem('judgeNew_friend');  // 新用户session的值
    $('.guideShow').on("touchmove",function(e) {e.preventDefault();});
    oHeader.on("touchmove",function(e) {e.preventDefault();});
    oFooter.on("touchmove",function(e) {e.preventDefault();});

    // 回到过顶部
    oGoTop.hammer().on('tap',function() {
        oSlidePageScroll.eq(ajaxData.navIndex).stop().animate({scrollTop: '0'}, 250);
        oHeader.css({'top': 0}).find('.js_sildeNav').removeClass('active');
        myPub.HamstopPropaga();
    });

    // 关闭广告
    popCloseBtn.on('click',function(e) {
        $('.layer_Ads_index').hide();
         e.stopPropagation();
    });

    oSlideDown.hammer().on('tap',function () {
        oNewNavPop.show();
        // oShawdow.show();
    });

    oSlideUp.hammer().on('tap',function () {
        oNewNavPop.hide();
        // oShawdow.hide();
    })

    var categoryData, categoryNames;


    module.exports = {
        init:function(data,names) {
            categoryData = data;
            categoryNames = names;

            // 显不显示智能语音接口
            sfddjIndex.showAIEntrance();

            // 生成新的滑动页面html
            sfddjIndex.AppendSlidePage(names);

            // 重新定义
            oSlidePageScroll = $('.js_slidePageScroll');

            // 初始化左右滑动swiper
            sfddjIndex.SwiperSlide(names);

            // 初始化页面代码
            sfddjIndex.sfddjInit(true);

            // 历史记录初始化
            ajaxData.HistoryInit();

            // ajax请求前 锁定
            ajaxData.lockScroll();

            // 加载地区馆
            if( oSlidePageScroll.eq(ajaxData.navIndex).hasClass('areaListBox') ) {
                areaList.AreaListShow(function () {
                    // oLoadingPage.hide();
                    ajaxData.unlockScroll();
                    ajaxData.tabLoadOff[ajaxData.navIndex] = false;
                    ajaxData.SetSession();
                });
            }
            else {
                // 请求加载广告模块
                myAdsModel.adsAjax.AdsAjaxData(ajaxData.navIndex, categoryNames, function () {
                    // 请求加载产品
                    // ajax请求前 锁定
                    // ajaxData.lockScroll();
                    ajaxData.GoodsAjaxData(ajaxData.navIndex, true, function () {
                        // ajax请求前 锁定
                        ajaxData.unlockScroll();
                    });
                });
            }


            // 设置页面滚动事件
            sfddjIndex.ScrollPage();

            // 倒计时
            myAdsModel.adsInit.CutDataTime();

            // 检测需不需要弹出新人优惠券
            if(nNewFriend == 'newFriend'){
                // 弹出优惠券弹窗
                connectHtml.newFriendHtml();
            }else{
                // 获取弹窗
                myAdsModel.adsAjax.getPop();
            }

            // 产品懒加载  异步加载 调用这个
            lazLoading.AddLazLoadingImg(oSlidePageScroll[ajaxData.navIndex]);

            // 页面尺寸修改
            oWindow.on('resize',function() {
                if (resizeTimer) {
                    clearTimeout(resizeTimer)
                }
                resizeTimer = setTimeout(function(){
                    sfddjIndex.sfddjInit(true);
                }, 400);

            });

            // 页面跳转记录数据
            oWindow.unload(function(){
               ajaxData.SetSession();
            });
        }
    };


    var sfddjIndex = {
        // 页面swiper
        oSlidePageMain: '',
        nHeaderHeight: 0,
        nSearchBoxHeight: 0,
        nSildeNavHeight: 0,
        time_Scroll: null,           // 滚动计时器
        // 调整页面位置和初始化
        sfddjInit: function (bOff) {
            // bOff true 执行下面方法
            if(bOff) {
                sfddjIndex.SetSildeNavScroll();
                oContain.css({
                    'padding-top': 0,
                    'padding-bottom' : 0

                });
                oSlidePageScroll.css({
                    'height': oWindow.height() - oHeader.height() - oFooter.height(),
                    'padding-top': oHeader.outerHeight(true),
                    'padding-bottom' : oFooter.outerHeight(true)
                });
                myPub.SetImgHeight(oGoods_showTwo);
                sfddjIndex.slideNavPop();
            }
            oHeader.css({'top': 0}).find('.js_sildeNav').removeClass('active');
            oSideBox.stop().animate({'right': '-3.5rem'},300);
        },

        // 插入slide
        AppendSlidePage: function (name, fn) {
            var _className = '';
            var _advMainHtml = '<div class="AdvertMain jsAdvert"></div>';
            for(var i=0; i<name.length; i++) {

                if(name[i].replace(/\s/g,"") == '地区馆') {
                    _className = 'areaListBox';
                    _advMainHtml = '<div class="areaList js_areaList"></div>';
                }
                if(name[i].replace(/\s/g,"") == '返现专区') {

                    _className = 'memberCashBack';
                    _advMainHtml = '<div class="memberCashBackSon js_memberCashBack Height100"></div>';
                }

                oSlidePageWrap.append('<div class="swiper-slide js_slidePageScroll '+ _className +'"><div class="slidePageMain js_slidePageMain">'+ _advMainHtml +'</div></div>');
                ajaxData.pagearr.push(1);
                ajaxData.tabLoadOff.push(true);
                ajaxData.pageSCroll.push(0);
                ajaxData.loadFinish.push(false);
                ajaxData.dataStore[i+1] = [];
                ajaxData.dataStore_Off.push(true);

            }
            if(fn)fn();
        },

        // 初始加载滑动页面和添加导航信息
        SwiperSlide: function (data) {
            var _this = this;

            _this.oSlidePageMain = oSlidePage.swiper({
                pagination: oSildeNavUl[0],
                observe: true,
                observeParents: true,
                // onlyExternal: true,
                //threshold:50,
                touchAngle:20,
                paginationClickable: true,
                paginationBulletRender:function(index,className){
                    //添加导航
                    index == 0 ? names = '推荐' : names = data[index-1].replace(/\s/g,"");

                    return '<li class="'+className+'"><a>'+ names +'</a></li>';
                },
                onSlideChangeStart:function (swiper) {
                    var index = swiper.activeIndex;
                    if(ajaxData.tabLoadOff[index]){
                        oLoadingPage.show();
                    }
                    // _this.oSlidePageMain.destroy(false);
                    _this.oSlidePageMain.detachEvents();
                },
                // 滑动结束
                onSlideChangeEnd: function (swiper) {
                    var index = swiper.activeIndex;
                    ajaxData.navIndex = index;
                    ajaxData.lockScroll();
                    // 初始化页面 false 说明滚动不需要重置
                    sfddjIndex.sfddjInit(false);

                    // 同步滚动导航和页面滑动
                    _this.SildeNavScrollDis(index);
                    oSlidePageScroll.find('.js_slidePageMain').hide().eq(index).show();
                    //同步导航弹窗的选中内容
                    oNewNavPop.find('.js_newSlideNavLi').removeClass('active').eq(index).addClass('active');

                    lazLoading.DestroyLazLoadingImg();
                    lazLoading.AddLazLoadingImg(oSlidePageScroll[index]);

                    if(ajaxData.tabLoadOff[index]) {
                        // 地区馆添加
                        if(oSlidePageScroll.eq(index).hasClass('areaListBox')) {
                            areaList.AreaListShow(function () {
                                // oLoadingPage.hide();
                                ajaxData.tabLoadOff[index] = false;
                                ajaxData.unlockScroll();
                                ajaxData.SetSession();
                            });
                        }
                        //会员返现跳转
                        else if(oSlidePageScroll.eq(index).hasClass('memberCashBack')) {
                            myPub.locationHref('https://m.sfddj.com/returnCash/index');
                            ajaxData.unlockScroll();
                            sfddjIndex.oSlidePageMain.slideTo(0, 100);
                        }
                        // 请求加载广告
                        else {

                            myAdsModel.adsAjax.AdsAjaxData(index, categoryNames, function () {
                                ajaxData.GoodsAjaxData(index, true, function () {
                                    ajaxData.unlockScroll();
                                    ajaxData.tabLoadOff[index] = false;
                                    ajaxData.SetSession();
                                });
                            });
                        }
                    }
                    else {
                        ajaxData.unlockScroll();
                        ajaxData.tabLoadOff[index] = false;
                        ajaxData.SetSession();
                    }
                    _this.oSlidePageMain.attachEvents();
                }
            });
            //设置导航弹窗里的标题栏高度
            _this.slideNavPop();
        },

        //初始化导航弹窗内容
        slideNavInit: function () {
            var _this = this;
            //给导航弹窗加入内容
            oNewNavPop.find('.js_slideNavUl').append(connectHtml.slideNavHtml(categoryNames));
            // 初始化方法
            oNewNavPop.on('click',function (e) {
                e.preventDefault();
                var _tarTag = e.target;
                var $target;
                _tarTag.nodeName.toLowerCase() == 'li' ? $target = $(_tarTag) : $target = $(_tarTag).parents('li');
                if($target.hasClass('js_newSlideNavLi')){
                    var index = $target.attr('slideIndex');
                    oNewNavPop.find('.js_newSlideNavLi').removeClass('active');
                    $target.addClass('active');
                    sfddjIndex.oSlidePageMain.slideTo(index, 100);
                    oNewNavPop.hide();
                }

                //如果点击剩下的遮罩层隐藏弹窗
                if($target.hasClass('js_closeSlideNav')){
                    oNewNavPop.hide();
                }
            })

        },

        //初始化新加的导航弹窗
        slideNavPop: function () {
          var _this = this;
          //获取导航栏的高度
          var navH = oSildeNav.outerHeight(true);
          //先设置字体白色，因为刚打开其他没内容时会比较难看，导航加载完现在设置正常字体颜色
          $('.js_slideDown').find('.iconGoDown').css({color: '#323232'});
          oPackUpBox.css({height: navH});



        },

        // 设置导航宽度和滚动
        SetSildeNavScroll: function () {
            var sumLiWidth = 0;
            var oSildNavLi = oSildeNavUl.find('li');
            oSildNavLi.each(function (i) {
                sumLiWidth += oSildNavLi.eq(i).outerWidth(true) + 0.5
            });

            oSildeNavUl.css({
                'width' : Math.ceil(sumLiWidth)
            });

            nDisScrollLi = parseInt( (oSildeNavScroll.width() - oSildeNavUl.outerWidth(true))/(oSildNavLi.length-1) );

            if(oSildeNavJRoll.obj === undefined) {
                oSildeNavJRoll.AddScroll(oSildeNavScroll[0], {
                    scrollY: false,
                    scrollX: true
                });
            }
            else {
                oSildeNavJRoll.ReScroll()
            }


        },

        // 导航滚动和页面同步
        SildeNavScrollDis: function (index, callBack) {
            var _dis = 0;
            // 导航滚动
            if(index >= oSildeNavUl.find('li').length-3) {
                _dis = parseInt(oSildeNavScroll.width() - oSildeNavUl.width());
            }
            else if (index > 2) {
                _dis = nDisScrollLi * index
            }
            oSildeNavJRoll.ScrollTo(_dis, 0, 100);
            if(callBack)callBack();
        },

        // 滚动隐藏搜索
        ScrollPage: function () {
            var _this = this;
            var minScrHeight = 300;

            _this.nHeaderHeight = parseInt(oHeader.outerHeight(true));
            _this.nSearchBoxHeight = parseInt(oSearchBox.outerHeight(true));
            _this.nSildeNavHeight = parseInt(oSildeNav.outerHeight(true));

            oSlidePageScroll.off('scroll');
            oSlidePageScroll.on('scroll', function () {
                var afterScroll = $(this).scrollTop();

                // 滚动页面距离底部300像素 延迟150毫秒加载数据
                clearTimeout(_this.time_Scroll);
                _this.time_Scroll = setTimeout(function() {
                   // console.log(afterScroll)
                    var index = ajaxData.navIndex;

                    // 统计曝光数据
                    ddjAction.viewGoods( oSlidePageScroll.eq(index).find('.js_slidePageMain'), index );

                    // 防止开始滚动改变数据
                    if(!ajaxData.tabLoadOff[index]) {
                        // 设置缓存记录
                        ajaxData.pageSCroll[index] = afterScroll;
                    }


                    // 显示隐藏回到顶部侧边框
                    _this.ShowGoTop(afterScroll);
                    _this.ScrollHide(afterScroll);

                    // 添加地区馆
                    if(oSlidePageScroll.eq(index).hasClass('areaListBox')) return;

                    if(oSlidePageScroll[index].scrollHeight - afterScroll - oSlidePageScroll.height() < minScrHeight) {
                        // 设置翻页到最后一页 返回
                        if(ajaxData.loadFinish[index]) {
                            oSlidePageScroll.eq(index).find('.js_loadingBtn').hide().eq(0).show();
                            return;
                        }
                        // 加载产品数据  防止第一次加载出现2次问题
                        if(!ajaxData.tabLoadOff[index]) {
                            ajaxData.GoodsAjaxData(index, false, function () {
                                ajaxData.pagearr[index]++;
                            });
                        }
                    }
                }, 500);
            })

        },

        // 显示回到顶部按钮
        ShowGoTop: function (scrollTop) {
            scrollTop > 300 ? oSideBox.stop().animate({'right':0},300) : oSideBox.stop().animate({'right': '-3.5rem'},300);
        },

        // 页面滚动隐藏导航
        ScrollHide: function (scrollTop) {
            var _this = this;
            //console.log('scroll----:'+scrollTop);
            // 判断滚动距离隐藏搜索框和滚动方向 （不能提出成单独方法）
            if(scrollTop > _this.nHeaderHeight) {
                // oContain.css({'top':  _this.nSildeNavHeight});
                oHeader.css({'top': -_this.nSearchBoxHeight-1}).find('.js_sildeNav').addClass('active')
            }
            else {
                // oContain.css({'top':  _this.nHeaderHeight -1});
                oHeader.css({'top': 0}).find('.js_sildeNav').removeClass('active');
            }

        },

        // 判断显不显示智能语音的入口
        showAIEntrance: function () {
          var url = '/member/partition';
          G_JSON_POST(url,{},function (res) {
              // console.log('---',res);
              if(res == 0){
                  oAIEntrance.show();
              }
          },function (err) {

          })
        }

    }

    var ajaxData = {
        pagearr: [1],                   // 每个分页的翻页数
        pageSCroll: [0],                // 每个分页滚动高度
        tabLoadOff: [true],             // 左右滑动加载开关
        navIndex: 0,                    // 导航选中索引
        loadFinish: [false],            // 加载完成
        dataStore: {0: []},             // 数据存储
        dataStore_Off: [true],           // 数据存储调用开关
        loadAdsCount: 0,                // 加载计数
        locScrollTime: null,
        lockScroll: function () {
            var _this = this;
            _this.loadAdsCount ++;
        },

        unlockScroll: function () {
            var _this = this;
            _this.loadAdsCount --;
            // 检测数据请求完后执行
            if(_this.loadAdsCount == 0) {
                loadOver();
            }

            function loadOver() {
                clearTimeout(_this.locScrollTime);
                _this.locScrollTime = setTimeout(function () {
                    oLoadingPage.hide();
                    _this.HisScrollTop(_this.navIndex);
                    // 统计曝光数据
                    ddjAction.viewGoods( oSlidePageScroll.eq(_this.navIndex).find('.js_slidePageMain'), _this.navIndex );
                }, 300);
            }
        },

        // 设置商品数据
        GoodsAjaxData: function (index,isInit,fn) {
            var _this = this;
            var nowStart = 0;
            var nowLimit = 0;
            // console.log("index  " + index + "  isInit  " + isInit + "  page  " + ajaxData.pagearr[index]);

            if(index == 0 && isInit) {
                nowStart = perLimit;
                nowLimit = perLimit *  (ajaxData.pagearr[index] - 1);
            }
            else if(index == 0 && !isInit) {
                nowStart = perLimit * ajaxData.pagearr[index];
                nowLimit = perLimit;
                // if( ajaxData.pagearr[index] >= 2 ){
                //     nowStart = perLimit;
                //     nowLimit = perLimit *  (ajaxData.pagearr[index] - 1);
                // }else{
                //     nowStart = perLimit;
                //     nowLimit = perLimit;
                // }
            }
            else if(isInit){
                nowStart = 0;
                nowLimit = perLimit * ajaxData.pagearr[index];
            }
            else{
                nowStart = perLimit * ajaxData.pagearr[index];
                nowLimit = perLimit;
            }
            var dataUrl = BASE_URL;
            var dataJson = {};
            if(index == 0){
                dataUrl += "/shop/goods/loadGoods";
                dataJson = {groupName:GROUP_NAME,start:nowStart,limit:nowLimit};
            }
            else if(index <= categoryData.length){
                dataUrl += "/category/loadAll";
                dataJson = {categoryId:categoryData[index-1],start:nowStart,limit:nowLimit};
                // 用于 达观数据监测分类判断
                if(_this.tabLoadOff[index]) {
                    dataJson.is_first = 1;
                }
            }else{
                return;
            }

            // if(isInit) {
            //     _this.lockScroll()
            // }

            var _data = null;
            // console.log('设置数据', _this.dataStore[index] )
            // 从缓存中去值
            if ( _this.dataStore_Off[index] && _this.dataStore[index].length > 0 ) {
                _this.dataStore_Off[index] = false;
                _data = _this.dataStore[index];
                setGoodsList(_data, index);
                if(fn)fn();
            }
            else {
                _this.dataStore_Off[index] = false;
                G_JSON_POST(dataUrl, dataJson, function (data) {
                    // _data = data;
                    data.goodsList ? _data = data.goodsList : _data = data;
                    if( _data.length > 0 ) {
                        setGoodsList(_data, index);
                        _this.saveData(_data, index);
                    }

                    if(_data.length == 0 || _data.length < nowLimit ) {
                        oSlidePageScroll.eq(index).find('.js_loadingBtn').hide().eq(0).show();
                        ajaxData.loadFinish[index] = true;
                    }

                    if(fn)fn();

                }, function () {
                    // start
                }, function () {
                    // end
                    if(_data == null) {
                        if(fn)fn();
                    }
                });
            }

            function setGoodsList(argData, index) {
                if(index == 0) {
                    connectHtml.GoodsLiHtml(argData, index, 'showTwo')
                }
                else {
                    connectHtml.GoodsLiHtml(argData, index, 'showOne')
                }
            }

        },

        // 历史数据定位
        HistoryInit : function (fn1, fn2) {
            var _this = this;
            if(sessionStorage.getItem("navIndex") != null) {
                _this.navIndex = sessionStorage.getItem("navIndex")*1;
                _this.tabLoadOff[_this.navIndex] = false;
                sfddjIndex.SildeNavScrollDis(0, function() {
                    sfddjIndex.oSlidePageMain.slideTo(_this.navIndex, 100);
                });
                _this.GetSessionData();
                if(fn1) fn1(_this.navIndex);
            }
            else {
                // _this.tabLoadOff[0] = false;
                if(fn2) fn2();
            }
            // 给导航加上内容，须在导航索引更新之后
            sfddjIndex.slideNavInit();
        },

        // 历史滚动高度
        HisScrollTop: function (index) {
            var _this = this;
            oSlidePageScroll.eq(index).scrollTop(_this.pageSCroll[index]);
        },

        // 设置历史定位
        SetSession: function () {
            var _this = this;
            sessionStorage.setItem( "navIndex", JSON.stringify(_this.navIndex) );
            sessionStorage.setItem( "pagearr", JSON.stringify(_this.pagearr) );
            sessionStorage.setItem( "pageSCroll", JSON.stringify(_this.pageSCroll) );
            sessionStorage.setItem( "dataStore", JSON.stringify(_this.dataStore) );
        },

        // 通过历史数据设置初始数据
        GetSessionData: function() {
            var _this = this;
            var pageNum = sessionStorage.getItem("pagearr");
            var pageSCrollNum = sessionStorage.getItem("pageSCroll");
            var dataStoreList = sessionStorage.getItem("dataStore");

            if (pageNum != null) {
                // 设置页码数
                _this.pagearr = JSON.parse(pageNum);
            }

            if (pageSCrollNum != null) {
                // 设置页面滚动数据
                _this.pageSCroll = JSON.parse(pageSCrollNum);
            }

            if (dataStoreList != null) {
                // 设置历史商品数据
                _this.dataStore = JSON.parse(dataStoreList);
            }

        },

        // 存储历史数据
        saveData: function (data, index) {
            var _this = this;
            for(var i=0; i<data.length; i++) {
                _this.dataStore[index].push(data[i]);
            }
            // console.log('存储的数据',_this.dataStore);
        }



    }

    // 拼接HTML
    var connectHtml = {

        // 产品容器（并排和一排）
        GoodHtmlBox: function (data, bOff) {
            var _selet = bOff;          //showTwo 并排  showOne 是一排
            var shmtlBox = '';
            var shmtlLoad = '';
            var goodsOneClass = 'js_goods_showOne';
            var goodsTwoClass = 'active js_goods_showTwo';

            function  setGoodsHtmlBox(aClassName) {
                if(aClassName == goodsOneClass) {
                    shmtlLoad = '<div class="moreBtnBox">'+
                                    '<p class="loadingBtn js_loadingBtn" style="display:none;"><a>没有更多</a></p>'+
                                    '<p class="loadingBtn js_loadingBtn">'+
                                        '<span class="icon_loading icoStyle icon-spinner3 myRotateRefresh"></span>'+
                                        '<span>加载中</span>'+
                                    '</p>'+
                                '</div>';
                }
                return shmtlBox =   '<div class="goods_showChangeBox '+ aClassName +'">'+
                                        '<div class="goods_showChange">'+
                                            '<ul class="goodsList clearfix js_goodsList"></ul>'+
                                        '</div>'+
                                        shmtlLoad +
                                    '</div>';
            }

            if(_selet == 'showTwo') {
                return setGoodsHtmlBox(goodsTwoClass)
            }
            else if(_selet == 'showOne') {
                return setGoodsHtmlBox(goodsOneClass)
            }
            else {
                return setGoodsHtmlBox(goodsOneClass)
            }


        },

        // 并排产品列表
        GoodsLiHtml: function (data, iNow, showNum) {
            var _this = this;
            var shtml = '';
            var sfindClass = '';
            var _smallImgArg = smallImgArg;

           //  showNum == 'showTwo' ? sfindClass = 'js_goods_showTwo' : sfindClass = 'js_goods_showOne';

            if(showNum == 'showTwo') {
                sfindClass = 'js_goods_showTwo';
            }
            else {
                sfindClass = 'js_goods_showOne';
                _smallImgArg = smallImgArg200;

                // sAddCarHtml = '<p class="addCar js_addCar"><em class="icon-shopcar_small"></em></p>';
            }

            var oGoodsShowLi = oSlidePageScroll.eq(iNow).find('.'+ sfindClass +'');
            // 判断是否需要放入容器和标题
            if(oGoodsShowLi.length == 0) {
                // 插入产品容器
                oSlidePageScroll.eq(iNow).find('.js_slidePageMain').append(_this.GoodHtmlBox(data, showNum));
                oGoodsShowLi = oSlidePageScroll.eq(iNow).find('.'+ sfindClass +'');
                // _this.GoodHtmlBox = null;
                // 插入产品标题
                // oGoodsShowLi.prepend(myAdsModel.adsHtml.TitleHtml(data, 'time'))
            }

            for (var i=0; i<data.length; i++) {
                var goodsImgUrl = data[i].showImage != undefined ? (HTTP_IMAGE_URL + data[i].showImage) : (BASE_URL + '/static_v4/image/loadImg.jpg');

                // 全额保障  选择性显示哪些右上角图标
                var html_firstGueeImagePath = '';
                if(data[i].firstGueeImagePath!=null && data[i].firstGueeImagePath!=''){
                    html_firstGueeImagePath = '<div class="quanpei"><img src="'+data[i].firstGueeImagePath+'"alt="" /></div>';
                }

                // 新品 直降 单排名称前  双排左上角标记
                var html_goodsLabels_one = '';
                var html_goodsLabels_two = '';
                // 好吃 直降 底部提示
                var html_label = '';

                if(sfindClass == 'js_goods_showOne') {
                    if(data[i].goodsLabels && data[i].goodsLabels != ""){
                        html_goodsLabels_one = '<i class="promotionHotIcon">'+ data[i].goodsLabel +'</i>';
                    }

                    if(data[i].label && data[i].label != ''){
                        html_label = '<p class="promotionSale horpromotionSale">';
                        for(var j=0; j<data[i].labels.length; j++) {
                            html_label += '<i>'+data[i].labels[j]+'</i>'
                        }
                        html_label += '</p>';
                    }
                }


                if(sfindClass == 'js_goods_showTwo') {
                    if (data[i].goodsLabels && data[i].goodsLabels != "") {
                        html_goodsLabels_two =
                            '<div class="verpromotionHot">' +
                            '   <span>' + data[i].goodsLabel + '</span>' +
                            '   <div><img src="' + BASE_URL + '/static_v4/image/iconImg/hotIcon.png" alt=""></div>' +
                            '</div>';
                    }
                }


                // 团购标记
                var html_isTuangou = '';
                if(data[i].isTuangou){
                    html_isTuangou =
                        '<span class="goodsPrice">￥' + data[i].tuangouPrices + '</span>'+
                        '<span class="tuangouNum">/<span>￥' + data[i].salePrice + '</span></span>'
                }else{
                    html_isTuangou = '<span class="goodsPrice">￥' + data[i].salePrice + '</span>'
                }

                // 达观数据设置
                var datagrandHref = '';
                var datagrandRequestId = '';
                var datagrandAddCar = '';
                var datagrandSceneType = '';
                if( data[i].requestId && data[i].requestid != 'undefined' && data[i].requestid != 'null' ) {
                    if(iNow > 0) {
                        datagrandHref = '?goodschannel=datagrand&recRequestId=' + data[i].requestId;
                        datagrandAddCar = 'goodschannel=datagrand';
                        // datagrandSceneType = 'sceneType=cate';
                    }
                    datagrandRequestId = data[i].requestId
                }
                else {
                    if(iNow > 0) {
                        datagrandHref = '?goodschannel=not_datagrand';
                        datagrandAddCar = 'goodschannel=not_datagrand';
                    }
                }

                if(iNow > 0) {
                    datagrandSceneType = 'sceneType=cate';
                }



                shtml +=
                        '<li>' +
                        '   <a class="BoxSelf" href="' + BASE_URL + '/h/goodspay/goodsView/' + data[i].goodsSn + datagrandHref + '" data-growing-title="'+data[i].name+'" requestId="'+ datagrandRequestId +'" goodsId="'+ data[i].id +'" '+ datagrandSceneType +'>'+
                        '       <figure>'+
                        '           <img class="js_lazyImg" data-echo="' + goodsImgUrl + _smallImgArg +'" ' +
                        '           src="' + BASE_URL + '/static_v4/image/loadImg.jpg">' +
                                    html_firstGueeImagePath +
                                    html_goodsLabels_two +
                                    // '<i class="tip-info">' + data[i].discount + '</i>'+
                        '       </figure>' +
                        '       <aside class="priceArea VBox Bflex1">'+
                        '           <div class="Bflex1 priceArea_name">'+
                        '               <h4>' + html_goodsLabels_one + data[i].name + '</h4>'+
                        '               <p class="smallFont_tip">' + data[i].title + '</p>'+
                        '           </div>'+
                        '           <div class="priceArea_price">'+
                    // '                <i class="tip-info">' + data[i].discount + '</i>'+
                        '               <p class="HBox priceAreaBox">' +
                    // '                <span class="goodsPriceOld">￥' + data[i].oldPrice + '</span>'+
                                        html_isTuangou +
                        '               </p>'+
                        '           </div>'+
                        '       </aside>'+
                        '   </a>' +
                        '   <p class="addCar js_addCar" pid="' + data[i].productId + '" requestId="'+ data[i].requestId +'" ' + datagrandAddCar + ' '+ datagrandSceneType +' ><em class="icon-shopcar_small"></em></p>' +
                            html_label +
                        '</li>';
            }

            var oShtml = $(shtml);
            oGoodsShowLi.find('.js_goodsList').append(oShtml);
            if(showNum == 'showTwo') {
                myPub.SetImgHeight(oShtml);
            }
            lazLoading.DestroyLazLoadingImg();
            lazLoading.AddLazLoadingImg(oSlidePageScroll[iNow]);
            shtml = null;
            // sAddCarHtml = null;
            data = null;
        },

        // 新人优惠券弹框
        newFriendHtml:function () {
            var shtml = '';
            var html_counponNewData = '';
            if(counponNewData && counponNewData.length > 0){
                for(var i = 0;i < counponNewData.length; i++){
                    var beginDate = myPub.FormatDateTime(new Date(counponNewData[i].beginDate),'minDay','.');
                    var endDate = myPub.FormatDateTime(new Date(counponNewData[i].endDate),'minDay','.');
                    html_counponNewData +=
                        '<div class="counponSin">'+
                        '   <div class="indexConBg">'+
                        '       <img src="' + BASE_URL + '/static_v4/image/invite/IndexConBg.png" alt="">'+
                        '   </div>'+
                        '   <div class="indexConTex HBox BoxCenter">'+
                        '       <div class="conTexLe">'+
                        '           <p class="conTexPrice">￥<span>'+ counponNewData[i].costPrice +'</span></p>'+
                        '           <p class="conTexTerm">'+ counponNewData[i].needPrice +'</p>'+
                        '       </div>'+
                        '       <div class="conTexRi Bflex1">'+
                        '           <p class="conTexDes">'+ counponNewData[i].couponName +'</p>'+
                        '           <p class="conTexTime">'+ beginDate +'-'+ endDate +'</p>'+
                        '       </div>'+
                        '   </div>'+
                        '</div>';
                }
            }else{
                html_counponNewData ='<p class="nullCou">注册成功，优惠券将在7日内到帐</p>'
            }


                shtml += '<div class="js_inviteAd layer_Ads layer_Ads_invite">'+
                        '   <div class="layer_Adsinvite">'+
                        '       <div class="layer_inviteImgBox">'+
                        '               <div class="inviteIndexBg">'+
                        '                   <img src="' + BASE_URL + '/static_v4/image/invite/invitenIdexF.png" alt="">'+
                        '               </div>'+
                        '               <div class="counponBg">'+
                        '                   <div class="couOverflow">' +
                                                html_counponNewData +
                        '                   </div>'+
                        '               </div>'+

                        '       </div>'+
                        '       <div class="layer_inviteCloseBtn">'+
                        '           <img class="js_layer_inviteCloseBtn" src="' + BASE_URL + '/static_v4/image/invite/inviteClose.png" alt="">'+
                        '       </div>'+
                        '   </div>'+
                        '</div>';

            var oShtml = $(shtml);
            oWrap.append(oShtml);

            var oInviteClose = $('.js_layer_inviteCloseBtn'); // 新人优惠券关闭按钮
            // 关闭新人优惠券弹窗
            oInviteClose.hammer().off('tap');
            oInviteClose.hammer().on('tap', function (e) {
                $('.layer_Ads_invite').hide();
                sessionStorage.removeItem('judgeNew_friend');
                sessionStorage.removeItem('judgeNew_friend_coupons');
                e.preventDefault();

            });
        },
        
        //导航弹窗内容
        slideNavHtml: function (data) {
            var newData = ['推荐'].concat(data);
            var shtml = '';
            for(var i = 0; i < newData.length; i++){
                var names = newData[i];
                var addClass = ajaxData.navIndex == i ? 'active' : '';
                shtml += '<li class="slideNavLi js_newSlideNavLi '+addClass+'"   slideIndex="'+i+'"><p class="slideNavLiCon">'+names+'</p></li>';
            }
            return shtml;
        }

    }
    
    // 用户行为     
    var ddjAction = {
        viewData: [],
        viewGoods: function (obj, iNow) {
            // 首页和分类区分
            var ddjActionPositionId = {};
            ddjActionPositionId.positionFirst = '首页';
            if(iNow > 0) {
                ddjActionPositionId.positionId = 2;
                ddjActionPositionId.positionSecond = categoryNames[iNow-1];
            }
            else {
                ddjActionPositionId.positionId = 1;
                ddjActionPositionId.positionSecond = '推荐';
            }

            // 统计曝光数据
            visualArea.viewEl.showViewEls( obj, function (data, dataJson) {
                ddjhoc.setData(data, 'rec_show', 'add', function () {
                    console.log('ddjhoc.params.rec_show.index', ddjhoc.params);
                    if( ddjhoc.params.length != 0 ) ddjhoc.sendData( ddjhoc.params );

                    console.log('ddjhoc.ddjParams.rec_show.index', ddjhoc.ddjParams);
                    if( ddjhoc.ddjParams.length != 0 ) ddjhoc.sendDDJData( ddjhoc.ddjParams );

                }, dataJson, ddjActionPositionId);
            });
        }
    }

});
